package com.lottery.utils;

import java.util.Set;

import com.lottery.service.pc28.accoutService.impl.LoaclauthServiceimpl;
import com.lottery.service.pc28.accoutService.impl.ManualCustomerServiceimpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class OnlineScanThread extends Thread {

	private boolean isLoop = true;

	private static final Logger logger = LoggerFactory.getLogger(OnlineScanThread.class);

	@Override
	public void run() {
		long endTime;
		// logger.debug("************check map thread start************");
		CustomerContext customerContext = CustomerContext.getInstance();
		while (isLoop) {
			try {
				// logger.debug("************isLooping************");
				endTime = System.currentTimeMillis() / 1000;
				Set<Integer> set = LoaclauthServiceimpl.onlineMap.keySet();
				for (int id : set) {
					if (endTime - LoaclauthServiceimpl.onlineMap.get(id) > 25) {
						// logger.debug("{} network timeout", id);
						LoaclauthServiceimpl.onlineMap.remove(id);
						LoaclauthServiceimpl.ssoMap.remove(id);
						customerContext.userFinishServer(id);
					}
				}

				set = ManualCustomerServiceimpl.onlineMap.keySet();
				for (int id : set) {
					if (endTime - ManualCustomerServiceimpl.onlineMap.get(id) > 25) {
						// logger.debug("{} network timeout", id);
						ManualCustomerServiceimpl.onlineMap.remove(id);
						LoaclauthServiceimpl.ssoMap.remove(id);
						customerContext.serverOffline(id);
					}
				}

				Thread.sleep(15000);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

}